package com.gemme.gemme.view;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.gemme.gemme.R;
import com.gemme.gemme.util.StrUtil;

import java.util.List;

public class ProductShaidanSingleView extends RelativeLayout {
    private Context context;
    public ProductShaidanSingleView(Context context) {
        this(context,null);
    }

    public ProductShaidanSingleView(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public ProductShaidanSingleView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context = context;
        initView();
    }
    ImageView iv_head;

    TextView tv_name;
    TextView tv_desc;
    TextView tv_content;

    ImageView iv1;
    ImageView iv2;
    ImageView iv3;

    private void initView() {
        LayoutInflater.from(context).inflate(R.layout.product_shaidan_single,this);
        iv_head = findViewById(R.id.iv_head);

        tv_name = findViewById(R.id.tv_name);
        tv_desc = findViewById(R.id.tv_desc);
        tv_content = findViewById(R.id.tv_content);

        iv1 = findViewById(R.id.iv1);
        iv2 = findViewById(R.id.iv2);
        iv3 = findViewById(R.id.iv3);


    }

    public void setData(ProShaidanBean.DataBean.RecordsBean recordsBean) {
        try {
            if(!StrUtil.isNUll(recordsBean.getHeadImgUrl()))
                Glide.with(context).load(recordsBean.getHeadImgUrl()).into(iv_head);
            Log.e("@@@@@",""+recordsBean.getUsername());
            if(recordsBean.getNickname()!=null){
                tv_name.setText(StrUtil.noNUll(recordsBean.getNickname()));
            }else {
                String text = recordsBean.getUsername();
                String sub_str = null;
                sub_str = text.substring(3, 7);
                text = text.replace(sub_str, "****");
                tv_name.setText(StrUtil.noNUll(text));
            }

            tv_desc.setText(StrUtil.noNUll("规格:"+recordsBean.getSpecValue()));
            tv_content.setText(StrUtil.noNUll(recordsBean.getCommentContent()));

            List<String> pictureList = recordsBean.getPictureList();
            for (int i = 0; i < pictureList.size(); i++) {
                String s = pictureList.get(i);
                if(StrUtil.isNUll(s))
                    continue;

                if(i == 0){
                    setPicture(iv1,s);
                }else if(i == 1){
                    setPicture(iv2,s);
                }else if(i == 2){
                    setPicture(iv3,s);
                }
            }
        }catch (Exception e){

        }
    }

    private void setPicture(ImageView iv, String s) {
        try {
            iv.setVisibility(VISIBLE);
            Glide.with(context).load(s).into(iv);
        }catch (Exception e){

        }
    }

}
